package org.zsl.mapper;


import org.apache.ibatis.annotations.*;
import org.apache.ibatis.mapping.FetchType;
import org.apache.ibatis.type.JdbcType;
import org.zsl.model.Product;

import javax.swing.*;
import java.util.List;

@Mapper
public interface ProductMapper {

    @Select("select * from product")
    @Results(id = "productMap"
            , value = {
            @Result(column = "product_id", property = "productId"
                    , jdbcType = JdbcType.INTEGER, id = true),
            @Result(column = "name", property = "name", jdbcType = JdbcType.VARCHAR),
            @Result(column = "price", property = "price", jdbcType = JdbcType.FLOAT),
            @Result(column = "brand", property = "brand", jdbcType = JdbcType.VARCHAR),
            @Result(column = "quantity", property = "quantity", jdbcType = JdbcType.INTEGER),
            @Result(column = "type_id", property = "category"
                    , one=@One(select = "org.zsl.mapper.CategoryMapper.selectById"
                    ,fetchType = FetchType.LAZY))

    })
    List<Product> selectAll();


    List<Product> selectByExample(Product product);

    @Select("select * from product where product_id = #{productId}")
    @ResultMap(value = "productMap")
    Product selectById(Integer productId);


    /**
     *   1. 增删改
     * */


    int update(Product product);

}
